﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace QD.Snapshot.Core.BLL.File
{
    public class Template
    {
        static Dictionary<string, string> dic { get; set; }
        public static string Get(string copyform)
        {
            if (dic.ContainsKey(copyform))
                return dic[copyform];
            return "";
        }

        public static void Init()
        {
            dic = new Dictionary<string, string>();
            dic.Add("0", ReadFile(string.Format("{0}template/wap/baidu.html", AppDomain.CurrentDomain.BaseDirectory, "0")));
            dic.Add("1", ReadFile(string.Format("{0}template/wap/so.html", AppDomain.CurrentDomain.BaseDirectory, "1")));
            dic.Add("2", ReadFile(string.Format("{0}template/wap/sogou.html", AppDomain.CurrentDomain.BaseDirectory, "2")));
            dic.Add("3", ReadFile(string.Format("{0}template/wap/bing.html", AppDomain.CurrentDomain.BaseDirectory, "3")));
            dic.Add("4", ReadFile(string.Format("{0}template/wap/guosou.html", AppDomain.CurrentDomain.BaseDirectory, "4")));
            dic.Add("5", ReadFile(string.Format("{0}template/wap/weixin.html", AppDomain.CurrentDomain.BaseDirectory, "5")));
            dic.Add("6", ReadFile(string.Format("{0}template/wap/shenma.html", AppDomain.CurrentDomain.BaseDirectory, "6")));
        }

        //读取模板内容
        static string ReadFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || (!System.IO.File.Exists(filePath)))
                return "";
            string s = "";
            try
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    s = sr.ReadToEnd();
                    sr.Close();
                }
            }
            catch { }
            return s;
        }
    }
}